package com.jushu.storbox.task.tqueue;

import java.util.ArrayList;
import java.util.List;

import com.jushu.storbox.callback.IUploadCallback;
import com.huawei.sharedrive.sdk.android.modelV2.response.FileInfoResponseV2;

public class UploadCallbackWrapper implements IUploadCallback {

	List<IUploadCallback> callBackList = new ArrayList<IUploadCallback>();
	
	@Override
	public void onStart() {
		synchronized(callBackList) {
			for(IUploadCallback callback : callBackList) {
				callback.onStart();
			}
		}
	}

	@Override
	public void onFailure(Throwable t) {
		synchronized(callBackList) {
			for(IUploadCallback callback : callBackList) {
				callback.onFailure(t);
			}
		}
	}

	@Override
	public void onSuccess(FileInfoResponseV2 successItem) {
		synchronized(callBackList) {
			for(IUploadCallback callback : callBackList) {
				callback.onSuccess(successItem);
			}
		}
	}

	@Override
	public void onProgress(int currentProgress, long currentSize, long maxSize) {
		synchronized(callBackList) {
			for(IUploadCallback callback : callBackList) {
				callback.onProgress(currentProgress, currentSize, maxSize);
			}
		}
	}

	@Override
	public void onStop() {
		synchronized(callBackList) {
			for(IUploadCallback callback : callBackList) {
				callback.onStop();
			}
		}
	}

	@Override
	public void onCanceled() {
		synchronized(callBackList) {
			for(IUploadCallback callback : callBackList) {
				callback.onCanceled();
			}
		}
	}

	@Override
	public void onDettach() {
		synchronized(callBackList) {
			for(IUploadCallback callback : callBackList) {
				callback.onDettach();
			}
		}
	}

	public void registerCallback(IUploadCallback callback) {
		synchronized(callBackList) {
			if(!callBackList.contains(callback)) {
				callBackList.add(callback);
			}
		}
	}
	
	public void unRegisterCallback(IUploadCallback callback) {
		synchronized(callBackList) {
			if(callBackList.contains(callback)) {
				callBackList.remove(callback);
			}
		}
	}
}
